<template>
  <div class="top">
    <div class="filter-container" :class="{ fold: show }">
      <el-row v-for="item in LabelData">
        <el-col :span="2" class="filter-label el-col-2"
          ><div>{{ item.label }}</div></el-col
        >
        <el-col :span="22"
          ><div
            class="select-List"
            v-for="Idx in item.choises"
            @click="labelList(item.choises, Idx)"
            :class="{ 'is-active': Idx.isActive }"
          >
            {{ Idx.name }}
          </div></el-col
        >
      </el-row>
      <!-- <div class="button" v-if="isSHow">
        <span @click="reset">重置</span>
      </div> -->
    </div>
    <p>
      <el-link :underline="false" class="btn" @click="show = !show"
        ><span>{{ show ? "展开全部" : "收起" }}</span>
      </el-link>
    </p>
  </div>
  <div>
    <el-card class="mt-10">
      <div class="sorts">
        <el-row>
          <el-col :span="3"
            ><el-link
              @click="tabChange(1)"
              :underline="false"
              :class="activeTab === 1 ? 'active' : ''"
              >{{ activeTab === 1 ? "综合排序" : "综合" }}</el-link
            ></el-col
          >
          <el-col :span="3"
            ><el-link
              @click="tabChange(2) "
              :underline="false"
              :class="activeTab === 2 ? 'active' : ''"
              >{{ activeTab === 2 ? "销量由高到低" : "销量" }}</el-link
            ></el-col
          >
          <el-col :span="3" v-if="tag === 6"
            ><el-link
              @click="tabChange(6)"
              :underline="false"
              :class="activeTab === 6 ? 'active' : ''"
              >{{ activeTab === 6 ? "评价由高到低" : "评价" }}</el-link
            ></el-col
          >
          <el-col :span="3"
            ><el-link
              @click="tabChange(3)"
              :underline="false"
              :class="activeTab === 3 ? 'active' : ''"
              >{{ activeTab === 3 ? "浏览量由高到低" : "浏览量" }}</el-link
            ></el-col
          >
          <el-col :span="3"
            ><el-dropdown>
              <span class="el-dropdown-link" style="font-size: initial">
                价格<el-icon class="el-icon--right"><arrow-down /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item><span>价格由高到低</span></el-dropdown-item>
                  <el-dropdown-item><span>价格由低到高</span></el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
          <el-col :span="3" v-if="tag === 5"
            ><el-link
              @click="tabChange(5)"
              :underline="false"
              :class="activeTab === 5 ? 'active' : ''"
              >{{ activeTab === 5 ? "发布时间由近及远" : "发布时间" }}</el-link
            ></el-col
          >
          <el-col :span="3" v-if="tag === 7"
            ><el-link
              @click="tabChange(7)"
              :underline="false"
              :class="activeTab === 7 ? 'active' : ''"
              >{{ activeTab === 7 ? "开课日期由近及远" : "开课时间" }}</el-link
            ></el-col
          >
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { ElMessage } from "element-plus";

export default defineComponent({
  name: "",
});
</script>

<script setup lang="ts">
import { onMounted } from "vue";
import { ref } from "vue";
import { useChoisesVideoStore } from "@/store/discovery";
const show = ref(true);
const LabelData = ref<any>([]);
const isSHow = ref(false);

// let isActiveList = ref<any>([])
// 视频标签仓库
const ChoisesVideoStore = useChoisesVideoStore();

const getChoisesVideoStore = async () => {
  await ChoisesVideoStore.getChooseList();
  LabelData.value = ChoisesVideoStore.choisesLabelAllList;
  // console.log(LabelData);
};

defineProps(["tag"]);
//控制展开
const activeTab = ref(1);
const activeList = ref<any>([]);
let ins = ref(1);

// 点击tab切换
const tabChange = (index: number) => {
  ins.value = index;
  activeTab.value = index;
};

// 标签筛选
const labelList = (choises: any, Idx: any) => {
  if (!Idx.isActive) {
    activeList.value = choises.filter((item: any) => item.isActive);
    console.log(activeList.value);
    if (activeList.value.length >= 3)
      return ElMessage("同一筛选条件最多选择3个");
  }
  Idx.isActive = !Idx.isActive;
  const re = choises.find((item: any) => item.isActive);
  if (re) {
    isSHow.value = true;
  } else {
    isSHow.value = false;
  }


};

// 重置按钮
const reset = () => {
  console.log(activeList)
  activeList.value.forEach((item:any)=>{
    item.isActive = false;
  })
  console.log()

  isSHow.value = false;
};



onMounted(() => {
  // 获取标签列表
  getChoisesVideoStore();
});
</script>

<style lang="scss" scoped>
.button {
  position: absolute;
  padding: 3px 0;
  top: 35px;
  right: 30px;
  cursor: pointer;
  color: #f93684;
}
.active {
  color: #f93684;
}
.is-active {
  color: #fff !important;
  background-color: #f93684;
}

.el-link:hover {
  color: #f93684;
  text-decoration: none;
}
.sorts {
  text-decoration: none;
}
.btn {
  text-align: center;
  color: #f93684;
}

.is-active {
  color: #f93684;
}
.filter-container {
  margin-top: 10px;
  padding: 26px 30px 0;
  border-radius: 4px;
  background-color: #fff;
  position: relative;
  overflow: hidden;
}

.top {
  border-radius: 4px;
  background-color: #fff;
  margin-bottom: 10px;
  position: relative;
}
.el-row:after,
.el-row:before {
  display: table;
  content: "";
}
.fold {
  height: 170px;
}

.vip-header-container {
  width: 1140px;
  margin: 15px auto 10px auto;
  color: #111;
  background-color: #fff;
  margin-top: 15px;
  /* margin-bottom: 10px; */
  border-radius: 4px;
  padding: 20px 30px 16px;
}

p {
  text-align: center;
  color: #f93684;
  font-size: 14px;
  padding-bottom: 10px;
}
span {
  cursor: pointer;
}

.el-row {
  margin-bottom: 20px;
}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
  color: #b1b5c1;
  padding: 7px 0;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.el-col-22 {
  background-color: #fff;
}
.select-item {
  // background-color: rgb(221, 233, 128);
  display: inline-block;
  cursor: pointer;
  font-size: 14px;
  border-radius: 4px;
  padding: 7px 13px;
  user-select: none;
  margin-right: 24px;
  margin-bottom: 10px;
}

.select-List {
  display: inline-block;
  cursor: pointer;
  font-size: 14px;
  border-radius: 4px;
  color: #b1b5c1;
  padding: 7px 13px 7px;
  user-select: none;
  margin-right: 24px;
  margin-bottom: 10px;
}

.filter-label {
  font-size: 14px;
  margin-top: 6px;
}
</style>
